package org.test.hadoop.minicluster.start;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.yarn.server.MiniYARNCluster;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author: chengjj
 * @Date: 2020-07-01
 */
public class MiniClusterStarter {
    public static void main(String[] args) throws IOException {
        //System.setProperty("hadoop.home.dir", "E:/test/hadoop/");
        //System.out.println(System.getenv());
        //System.load("E:\\resource\\bigdata\\winutils-master\\hadoop-3.2.1\\bin\\hadoop.dll");
        //System.out.println(System.getProperty("java.library.path"));
        //System.loadLibrary("hadoop");
        Configuration conf =new Configuration();

        File tempDir =  /*Files.createTempDir();*/new File("E:/test/hadoop/tmp");

        conf.setBoolean(DFSConfigKeys.DFS_PERMISSIONS_ENABLED_KEY, false);
        conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, false);
        //conf.set(DFSConfigKeys, null);
        //conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_SUPPORT_ALLOW_FORMAT_KEY, false);
        conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_POSIX_ACL_INHERITANCE_ENABLED_KEY, false);
        conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, tempDir.getAbsolutePath());
        conf.setBoolean("dfs.permissions", false);
        conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, "E:/test/hadoop/dfs/na");
        //System.setProperty("test.build.data", hdfsTempDir);
        MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf);
        builder.nameNodeHttpPort(8081);
        builder.format(false);
        builder.build();

        MiniYARNCluster yrCluster =new MiniYARNCluster("test",1,1,1);
        yrCluster.init(conf);
        yrCluster.start();

        yrCluster.getConfig().writeXml(new FileOutputStream(new File("E:/test/hadoop/conf.xml")));
    }
}
